Skip to content

Add: Implement Merge Sort algorithm in C++ #183

Merged
Pradeepsingh61 merged 2 commits intomainfrom
add-dsa-implementations
Oct 1, 2025
Merged

Add: Implement Merge Sort algorithm in C++ #183
Pradeepsingh61 merged 2 commits intomainfrom
add-dsa-implementations

Conversation

@Karanjot786
Copy link
Copy Markdown
Collaborator

🎃 Hacktoberfest 2025 Contribution

📌 Summary

This PR adds a comprehensive implementation of the Merge Sort algorithm in C++ to enhance the repository's
sorting algorithms collection.

🚀 What's Added

  • File: CPP/algorithms/sorting/merge_sort.cpp
  • Complete merge sort implementation using divide-and-conquer approach
  • Well-documented code with detailed comments
  • Example usage and test cases included

📊 Algorithm Details

  • Time Complexity: O(n log n) in all cases (best, average, worst)
  • Space Complexity: O(n) for temporary array storage
  • Algorithm Type: Divide and Conquer
  • Stability: Stable sorting algorithm

✨ Key Features

  • ✅ Clear function documentation
  • ✅ Step-by-step implementation comments
  • ✅ Example output demonstration
  • ✅ Test cases covering edge scenarios
  • ✅ Follows repository naming conventions (snake_case)

🧪 Testing

The implementation includes test cases for:

  • Empty arrays
  • Single element arrays
  • Already sorted arrays
  • Reverse sorted arrays
  • Arrays with duplicate elements

📚 Code Quality

  • Clean, readable code structure
  • Comprehensive inline comments
  • Proper function separation (merge, mergeSort, utility functions)
  • Example usage in main function

🎯 Contribution Type

  • Algorithm Implementation
  • Documentation
  • Code Examples
  • Following contribution guidelines

@github-actions
Copy link
Copy Markdown

🎉 Welcome to Hacktoberfest 2025, @Karanjot786! 🎃

Thank you for your first contribution to our DSA repository! Here's what happens next:

🔍 Automatic Checks

  • Code Validation: Passed
  • 🧪 Compilation Tests: Passed

📋 Next Steps

🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon.

🎁 What You Get

  • 🏆 Hacktoberfest Credit: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
  • 🌟 Hall of Fame: You'll be featured in our contributors list
  • 📚 Learning: Code review feedback from experienced developers

💡 Tips for Success

  • Follow our Contributing Guidelines
  • Add comments explaining your algorithm
  • Include time/space complexity analysis
  • Test your code before submitting

Welcome to the community! 🚀

@github-actions
Copy link
Copy Markdown

🤖 Automated PR Status

🔍 Code Validation

Passed - File naming and structure look good!

🧪 Compilation Tests

Passed - All code compiles successfully!

📋 Overall Status

🎉 Ready for Review - Your PR has passed all automated checks!
👥 Maintainers have been notified for review.


This comment was generated automatically. Checks will re-run when you push new commits.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a complete Merge Sort algorithm in C++ as part of Hacktoberfest 2025 contributions. The implementation follows the divide-and-conquer approach with comprehensive documentation and example usage.

Key Changes

  • Added complete merge sort implementation with O(n log n) time complexity
  • Included well-documented functions with detailed comments and parameter descriptions
  • Provided example usage, test cases, and expected outputs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

cout << "Original array: ";
printArray(arr);

mergeSort(arr, 0, arr.size() - 1);
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential integer underflow when arr.size() is 0. Since arr.size() returns size_t (unsigned), subtracting 1 from 0 results in a very large positive number. This should be guarded with an empty array check or cast arr.size() to int before subtraction.

Suggested change
mergeSort(arr, 0, arr.size() - 1);
if (!arr.empty()) {
mergeSort(arr, 0, arr.size() - 1);
}

Copilot uses AI. Check for mistakes.

#include <iostream>
#include <vector>
using namespace std;
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using 'using namespace std;' in header files or example code is considered bad practice as it pollutes the global namespace. Consider using specific using declarations like 'using std::vector;' or fully qualified names.

Copilot uses AI. Check for mistakes.
@Karanjot786 Karanjot786 changed the title Add: Implement Merge Sort algorithm in C++ Add: Implement Merge Sort algorithm in C++ Sep 30, 2025
@github-actions
Copy link
Copy Markdown

🎉 Welcome to Hacktoberfest 2025, @Karanjot786! 🎃

Thank you for your first contribution to our DSA repository! Here's what happens next:

🔍 Automatic Checks

  • Code Validation: Passed
  • 🧪 Compilation Tests: Passed

📋 Next Steps

🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon.

🎁 What You Get

  • 🏆 Hacktoberfest Credit: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
  • 🌟 Hall of Fame: You'll be featured in our contributors list
  • 📚 Learning: Code review feedback from experienced developers

💡 Tips for Success

  • Follow our Contributing Guidelines
  • Add comments explaining your algorithm
  • Include time/space complexity analysis
  • Test your code before submitting

Welcome to the community! 🚀

@github-actions
Copy link
Copy Markdown

🤖 Automated PR Status

🔍 Code Validation

Passed - File naming and structure look good!

🧪 Compilation Tests

Passed - All code compiles successfully!

📋 Overall Status

🎉 Ready for Review - Your PR has passed all automated checks!
👥 Maintainers have been notified for review.


This comment was generated automatically. Checks will re-run when you push new commits.

@Pradeepsingh61 Pradeepsingh61 merged commit 465b14f into main Oct 1, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants